<template>
    <div>
        <van-nav-bar title="搜索页" left-text="返回" left-arrow @click-left="onClickLeft" />
        <van-search v-model="q" show-action placeholder="请输入搜索关键词" @search="onSearch">
            <template #action>
                <div @click="onClickButton">搜索</div>
            </template>
        </van-search>
        <ul>
            <li v-for="item in list" :key="item.id">
                <img :src="item.img" alt="">
                <h4>{{ item.title }}</h4>
            </li>
        </ul>
    </div>
</template>

<script setup>
import axios from 'axios';
import { onMounted, ref } from 'vue';

const onClickLeft = () => history.back();

const q = ref('')
const list = ref([])

const onSearch = (val) => {
    console.log(val);
    q.value = val
    getList()
    
}
const onClickButton = () => {
    console.log(123);
}

const getList = () => {
    axios.get('/api/list2', { params: { q: q.value } }).then(res => {
        list.value = res.data
    })
}

onMounted(() => {
    getList()
})

</script>